﻿using System;

namespace 装甲部队验证服务端
{
    public class Heatsend
    {
        public long Lastrevicetime;//上一次的发送时间
        public long Indextime=5000;//发送间隔时间,从接收到后开始算
        public long Lastsendtime;//上一次接收时间
        public long Nowtime;

        public long Maxlosttime=30000;//超时时间
        public long Lostcount = 0;//超时次数
        private long MaxLostcount = 0;

        public bool Isrecvice=false;
        public Heatsend()
        {
        }
        public void Cheaklost()
        {
            if (NowTime() >= Lastrevicetime + Maxlosttime&&!Isrecvice)
            {
                Lostcount++;
            }
            if (Isrecvice&& NowTime() <= Lastrevicetime + Maxlosttime)
            {
                Lastrevicetime = NowTime();
                Lostcount = 0;
                
            }
            
        }
        public bool IsConnect()
        {
            if (Lostcount > MaxLostcount)
            {
                return false;
            }
            else
            {
                return true;
            }

        }

        public long NowTime()
        {

            //获取当前Ticks

            long currentTicks = DateTime.Now.Ticks;

            DateTime dtFrom = new DateTime(1970, 1, 1, 0, 0, 0, 0);

            long currentMillis = (currentTicks - dtFrom.Ticks) / 10000;

            return currentMillis;
        }
    }
}